package com.mdd.common.config.map;

import com.github.xiaoymin.map.MapClientConfig;
import com.mdd.common.entity.system.SystemConfig;
import com.mdd.common.mapper.system.SystemConfigMapper;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import javax.annotation.Resource;

/**
 * @ClassName MapConfig
 * @Description
 * @Autore Slien.zuo
 * @Date 2022/12/5 18:30
 * @Version 1.0
 **/
@Configuration
@MapperScan({"com.mdd.common.mapper.system"})
@DependsOn({"systemConfigMapper"})
public class MapConfig {

    @Resource
    private SystemConfigMapper systemConfigMapper;

    @Bean
    public LikeTenCentClient mapClient() {
        SystemConfig config = systemConfigMapper.selectByTypeAndName("website_map_key", "tencent_map_key");
        MapClientConfig mapClientConfig = new MapClientConfig();
        if (config != null) {
            String key = config.getValue();
            // 腾讯地图配置
            if (StringUtils.isNotEmpty(key)) {
                mapClientConfig.keysTencentMap(key);
            }
        }
        return new LikeTenCentClient(mapClientConfig);
    }
}
